import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex) // vue的插件机制

// Vuex.Store 构造器选项
const store = new Vuex.Store({
	// 为了不和页面或组件的data中的造成混淆，state中的变量前面建议加上$符号

	state: {
		// 用户信息
		$userInfo: {},
		$token: '',
		$agent_id: '',
		$isLogin: false,
		$config: {},
		$share: {},
		$style: {},
		$userToken: '',
		$systemConfig: {}, 			//平台配置
		$gainInfo: { 				//取车地址信息
			cityId: 0,
			city: '',
			title: '',
			address: '',
			type: 0,
			store: 0,
			storeName: '',
			screenStore: '', 		//用于筛选坐标的车辆
			lat: 0,
			lng: 0,
		},
		$backInfo: { //还车地址信息
			cityId: 0,
			city: '',
			title: '',
			address: '',
			type: 0,
			store: 0,
			storeName: '',
			screenStore: '', 		//用于筛选坐标的车辆
			lat: 0,
			lng: 0,
		},
		$startDate: { 				//取车时间
			text: "",
			date: "",
			time: "",
			timestamp: 0,
		},
		$endDate: { 				//还车时间
			text: "",
			date: "",
			time: "",
			timestamp: 0,
		},
		$backCarShow:true,			//是否异地还车
		$diffday:0, 				//租车天数
		$carID: 0, 				//选择汽车套餐
		$isDrive:0, 				//代驾状态
	},
	getters: {

	},
	mutations: {
		login(state, provider) { 		//改变登录状态 
			state.$isLogin = true
			state.$userInfo = provider.member
			state.$token = provider.token
			uni.setStorage({ 		//将用户信息保存在本地  
				key: 'userInfo',
				data: provider
			})
		},
		loginout(state) { 			//退出登录
			state.$isLogin = false
			state.$userInfo = {}
			state.$token = ''
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		//缓存分销用户ID
		setAgentID(state, data) {
			state.$agent_id = data
		},
		//设置取车数据
		setGain(state, data) {
			state.$gainInfo = data
		},
		//设置还车数据
		setBack(state, data) {
			state.$backInfo = data
		},
		//设置系统配置
		setConfig(state, data) {
			state.$style = data.theme
			state.$config = data
		},
		//设置分享参数
		setShare(state, data) {
			state.$share = data
		},
		//设置取车时间
		setStartDate(state, data) {
			state.$startDate = data
		},
		//设置还车时间
		setEndDate(state, data) {
			state.$endDate = data
		},
		//设置租车天数
		setDiffDay(state, data) {
			state.$diffday = data
		},
		//设置代驾状态
		setDaijia(state, data) {
			state.$isDrive = data===true?1:0;
		},
		//设置异地还车状态
		setBackCar(state, data) {
			state.$backCarShow = data
		},
		//选中汽车ID
		setCarID(state, id) {
			state.$carID = id
		},
		//缓存续租订单里面的数据
		setReletOrder(state,data){
			let order=data.order
			let endDate=data.end_date
			this.state.$gainInfo= {
				city: '',
				title: order.gain_name,
				address: order.gain_address,
				type: order.gain_type,
				store: order.gain_store,
				storeName: order.gain_name,
				screenStore: '',
				lat: order.gain_lat,
				lng: order.gain_lng,
			},
			this.state.$backInfo= { //还车地址信息
				city: '',
				title: order.back_name,
				address: order.back_address,
				type: order.back_type,
				store: order.back_store,
				storeName: order.back_name,
				screenStore: '',
				lat: order.back_lat,
				lng: order.back_lng,
			},
			this.state.$startDate= { //取车时间
				text: order.end_day.times,
				date: order.end_day.date,
				time: order.end_day.time,
				timestamp: order.end_day.timestamp,
			},
			this.state.$endDate = endDate
			this.state.$carID=order.car_id
		},
		//缓存分享订单里面的数据
		setShareOrder(state,data){
			let order=data.order
			this.state.$gainInfo= {
				city: '',
				title: order.gain_name,
				address: order.gain_address,
				type: order.gain_type,
				store: order.gain_store,
				storeName: order.gain_name,
				screenStore: '',
				lat: order.gain_lat,
				lng: order.gain_lng,
			},
			this.state.$backInfo= { //还车地址信息
				city: '',
				title: order.back_name,
				address: order.back_address,
				type: order.back_type,
				store: order.back_store,
				storeName: order.back_name,
				screenStore: '',
				lat: order.back_lat,
				lng: order.back_lng,
			},
			this.state.$startDate= {
				text: order.start_date.times,
				date: order.start_date.date,
				time: order.start_date.time,
				timestamp: order.start_date.timestamp,
			},
			this.state.$endDate= {
				text: order.end_date.times,
				date: order.end_date.date,
				time: order.end_date.time,
				timestamp: order.end_date.timestamp,
			},
			this.state.$carID=order.car_id
		},
		//清空下单信息
		clearRental(state) {
			state.$gainInfo = {
					title: '',
					address: '',
					type: 0,
					store: 0,
					storeName: '',
					lat: 0,
					lng: 0,
			},
			state.$backInfo = {
				title: '',
				address: '',
				type: 0,
				store: 0,
				storeName: '',
				lat: 0,
				lng: 0,
			},
			state.$startDate = {
				text: "",
				date: "",
				time: "",
				timestamp: 0,
			},
			state.$endDate = {
				text: "",
				date: "",
				time: "",
				timestamp: 0,
			},
			state.$carID = 0,
			state.$isDrive = 0
		},
		//还车参数同步取车参数数据
		synGainData(){
			this.state.$backInfo = this.state.$gainInfo;
		}
	},
	actions: {

	}
})

export default store
